package com.code.question1;

import com.code.question1.controller.StudentController;
import com.code.question1.impl.Student;
import com.code.question1.impl.StudentAgeException;
import com.code.question1.impl.StudentNoException;

import java.io.*;
import java.util.List;

public class Client {
    public static void main(String[] args) {
        //初始化学生信息
        StudentController sc=new StudentController();
        try {
            sc.InitStudents();
        } catch (StudentAgeException | IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
        Student student = new Student();
        System.out.println("**************************************************");
        System.out.println("*                                                *");
        System.out.println("*                拉勾学生管理系统                 *");
        System.out.println("*                                                *");
        System.out.println("**************************************************");
        //是否退出标识
        int flag = 1;
        System.out.println(student.toString());
        do {
            System.out.println("请输入要操作的功能编号：");
            System.out.println("1：新增学生信息");
            System.out.println("2：修改学生信息");
            System.out.println("3：查找学生信息");
            System.out.println("4：删除学生信息");
            System.out.println("5：全部学生信息");
            System.out.println("0：退出学生系统");
            String input = null;
            try {
                input = (new BufferedReader(new InputStreamReader(System.in))).readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                switch (input) {
                    case "1":
                        sc.AddStudent();
                        break;
                    case "2":
                        sc.UpdateStudent();
                        break;
                    case "3":
                        sc.FindStudents();
                        break;
                    case "4":
                        sc.DeleteStudent();
                        break;
                    case "5":
                        System.out.println(student.toString());
                        break;
                    default:
                        flag = 0;
                        sc.Logout(student);
                        System.out.println("谢谢使用！！");
                        break;
                }
            } catch (IOException e) {
                e.printStackTrace();
            } catch (StudentNoException e) {
                e.printStackTrace();
            } catch (StudentAgeException e) {
                e.printStackTrace();
            }
        } while (flag == 1);
    }
}
